<script type="text/javascript">
function mod_all_checkbox(class_name) {
    var i = 1;
    $('.'+class_name).each(function() {
        if (i==1) {
            if (this.checked == true) {
                i = 2;
            } else {
                i = 3;
            }
        }
        if (i == 3) {
            this.checked = false;
        } else {
            this.checked = true;
        }
    });
}

function change_check_all_status(class_name, check_all_id) {
    status = true;
    $('.'+class_name).each(function() {
        if (this.id == check_all_id) {
            check_all = this;
        } else {
            if (this.checked == false) {
                status = false;
            }
        }
    });
    if (status) {
        check_all.checked = true;
    } else {
        check_all.checked = false;
    }
}

function delete_users() {
    var ids = '';
    $("input[@type=checkbox]:checked").each(function() {
        if (this.value != '') {
            ids = ids + this.value;
        }
    });

    if (ids == '') {
        show_noticemessage('<?php __e('No conversations selected.'); ?>');
    } else {
        showItem('confirm_delete');
    }
}

function delete_users_now() {
    var ids = '';
    $("input[@type=checkbox]:checked").each(function() {
        if (this.value != '') {
            ids = ids + this.value + '|';
        }
    });
    var action = $("input[@name=delete_way]:checked").val();
    $.getJSON('<?php echo $html->admin_url('/users/ajax_delete_users/' . $page); ?>/'+action+'/'+ids, function(json_data) {
    hideItem('confirm_delete');
    $('#user_table_list').html(json_data.table_list);
    show_noticemessage(json_data.message);
    });
}
</script>
<div id="content">
    <ul class="inlinelist">
        <li class="prominent">
<?php 
if (!$has_group) {
    __e('You need to add a Group first');
    echo '</li>
    </ul>';
} else {
    echo $html->admin_link(__('Create a new user'), '/users/user_create');
?>
    </li>
    </ul>
<p></p>
<?php
if (!empty($users)) {
?>
  <form action="" id="list" method="post">

    <div style="display: none;" id="confirm_delete" class="d">
      <p class="warning"> <b> <?php __e('Are you sure you want to delete selected users?'); ?> 
         </b><br><br>
       <input type="radio" value="1" name="delete_way" id="inactive_user">  <label for="inactive_user"> <?php __e('Inactive users only'); ?> </label>&nbsp;&nbsp;&nbsp;&nbsp;<span class="err"> <?php __e('Just this user cant&#8217;t login.'); ?></span> <br>
        <input type="radio" value="2" name="delete_way" id="delete_user_only">  <label for="delete_user_only"> <?php __e('Delete users only'); ?> </label>&nbsp;&nbsp;&nbsp;&nbsp;<span class="err"> <?php __e('Delete users and keep posts.'); ?></span> <br>
        <input type="radio" value="3" name="delete_way" id="delete_user_and_posts">  <label for="delete_user_and_posts"> <?php __e('Delete users and posts'); ?> </label>&nbsp;&nbsp;&nbsp;&nbsp;<span class="err"> <?php __e('All posts in the user accounts will be lost.'); ?></span><br>
      </p>
      <input type="button" name="delete" value="<?php __e('Delete users'); ?>" onclick="delete_users_now();">
      <input type="button" name="Button" value="<?php __e('Cancel'); ?>" onclick="hideItem('confirm_delete');">
    </div>
<div id="user_table_list">
    <table>
      <tr>
        <th colspan="3" class="tablebar"> <input value="<?php __e('Delete users'); ?>" type="button" id="deleteT" onclick="delete_users();">
        </th>
        <td colspan="2" class="tablebar" align="right"><?php echo $pagelink; ?></td>
      </tr>
      <tr>
        <th><input value="" type="checkbox" name="select_all" id="select_all" class="chose_user" onclick="mod_allcheckbox_status2('user_id[]', this.checked);"></th>
        <th><?php __e('Username'); ?></th>
        <th><?php __e('Group'); ?></th>
        <th><?php __e('Last signed in'); ?></th>
        <th><?php __e('Status'); ?></th>

      </tr>
<?php

    foreach($users as $user) {
        $status = null;
        if ($user->status == 1) {
            $status = __('Active');
        } else if ($user->status == 2) {
            $status = __('Inactive');
        } else if ($user->status == 0) {
            $status = __('Deleted');
        }
        if ($user->is_superuser) {
            $group_title = __('Administrator');
        } else {
            $group_title = get_group_title($user->group_id);
        }
?>
      <tr class="">
        <td>
<?php
        if (!$user->is_superuser) {
?>
<input value="<?php echo $user->id; ?>" type="checkbox" name="user_id[]" class="chose_user" onclick="change_allcheckbox_status('user_id[]', 'select_all');" />
<?php
        }
?>
        </td>
        <td><?php echo $html->admin_link($user->username, '/users/user_edit/' . $user->id); ?></td>
        <td><?php echo $group_title; ?></td>
        <td><?php echo !empty($user->last_login) ? date('Y-m-d H:i', $user->last_login) : __('Never logged in'); ?></td>
        <td><?php echo $status; ?></td>

      </tr>
<?php
    }
?>
      <tr>
        <td colspan="3" class="tablebar"> <input value="<?php __e('Delete users'); ?>" type="button" id="deleteT" onclick="delete_users();">
        </td>
        <td colspan="2" class="tablebar" align="right"><?php echo $pagelink; ?></td>
      </tr>
    </table>
</div>
  </form>
<?php
} else {
    echo '<span class="new">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',__('There is no user right now.'),'</span>';
}
}
?>
</div>
